package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapeIot;
import com.ruoyi.grape.service.IGrapeIotService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物联网监测数据Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/iot")
public class GrapeIotController extends BaseController
{
    @Autowired
    private IGrapeIotService grapeIotService;

    /**
     * 查询物联网监测数据列表
     */
    @PreAuthorize("@ss.hasPermi('grape:iot:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapeIot grapeIot)
    {
        startPage();
        List<GrapeIot> list = grapeIotService.selectGrapeIotList(grapeIot);
        return getDataTable(list);
    }

    /**
     * 导出物联网监测数据列表
     */
    @PreAuthorize("@ss.hasPermi('grape:iot:export')")
    @Log(title = "物联网监测数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapeIot grapeIot)
    {
        List<GrapeIot> list = grapeIotService.selectGrapeIotList(grapeIot);
        ExcelUtil<GrapeIot> util = new ExcelUtil<GrapeIot>(GrapeIot.class);
        util.exportExcel(response, list, "物联网监测数据数据");
    }

    /**
     * 获取物联网监测数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:iot:query')")
    @GetMapping(value = "/{meteId}")
    public AjaxResult getInfo(@PathVariable("meteId") Long meteId)
    {
        return success(grapeIotService.selectGrapeIotByMeteId(meteId));
    }

    /**
     * 新增物联网监测数据
     */
    @PreAuthorize("@ss.hasPermi('grape:iot:add')")
    @Log(title = "物联网监测数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapeIot grapeIot)
    {
        return toAjax(grapeIotService.insertGrapeIot(grapeIot));
    }

    /**
     * 修改物联网监测数据
     */
    @PreAuthorize("@ss.hasPermi('grape:iot:edit')")
    @Log(title = "物联网监测数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapeIot grapeIot)
    {
        return toAjax(grapeIotService.updateGrapeIot(grapeIot));
    }

    /**
     * 删除物联网监测数据
     */
    @PreAuthorize("@ss.hasPermi('grape:iot:remove')")
    @Log(title = "物联网监测数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{meteIds}")
    public AjaxResult remove(@PathVariable Long[] meteIds)
    {
        return toAjax(grapeIotService.deleteGrapeIotByMeteIds(meteIds));
    }
}
